package main

import "fmt"

//map
func main() {
	//普通的初始化
	var map01 = make(map[string]string, 10)
	map01["ding"] = "yangwei"
	fmt.Println(map01, len(map01))
	fmt.Printf("%T", map01)
	//
	var map02 map[string]string
	map02 = make(map[string]string)
	fmt.Println(map02)
	//
	var map03 = map[string]string{
		"ding": "yangwei",
	}
	fmt.Println(map03)

	for s := range map03 {
		fmt.Println(s, map03[s])
	}

	for k, v := range map03 {
		fmt.Println(k, ":", v)
	}

	var map04 = map[int]int{
		1: 2,
		3: 4,
		2: 3,
		4: 5,
		5: 6,
	}

	for k, v := range map04 {
		fmt.Println(k, v)
	}

	//删除map中的kv
	delete(map04, 1)

	//值为map的切片
	var slice01 = make([]map[string]string, 10, 15)
	//使用时需要为每个索引对应的map进行初始化
	for i := range slice01 {
		slice01[i] = make(map[string]string, 10)
		slice01[i]["string"] = "dff"                   //
		slice01[i] = map[string]string{"ding": "yang"} //
	}

	fmt.Println(slice01)

	//值为切片的map
	var map05 = make(map[string][]string, 10)
	map05["ding"] = []string{"ding", "yang", "wei"}
	map05["yang"] = make([]string, 10, 11)
	map05["yang"][0] = "ding"

	fmt.Println(map05)
}
